package com.heima.wemedia.scan.listener;

import com.heima.common.constants.KafkaMessageConstant;
import com.heima.wemedia.scan.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class KafkaNewScanListener {

    @Resource
    private WmNewsAutoScanService wmNewsAutoScanService;

    @KafkaListener(topics = KafkaMessageConstant.NEWS_AUTO_SCAN_TOPIC,groupId = "newsAutoScan")
    public void newsAutoScan(ConsumerRecord<String,String> record){
        log.info("接收到文章审核的消息，消息内容：{}",record.value());
        String newsId = record.value();
        if (StringUtils.isNotBlank(newsId)) {
            log.info("开始进行文章审核-------------------");
            wmNewsAutoScanService.newsAutoScan(Long.valueOf(newsId));
            log.info("文章审核结束-----------------------");
        }
    }
}
